package com.bdqn.desiremall.command;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bdqn.desiremall.entity.Mall_ShoppingCart;
import com.bdqn.desiremall.serivce.shoppingcart.ShoppingcartService;
import com.bdqn.desiremall.serivce.shoppingcart.ShoppingcartServiceImpl;
import com.mvc.command.ICommand;

public class ShoppingCartServlet implements ICommand {
	//调用shoppingcart服务层
	//完成查询
	ShoppingcartService cartService=new ShoppingcartServiceImpl();
	public void carList(HttpServletRequest request,HttpServletResponse response){
			request.setAttribute("cartList", cartService.shoppingCartView(1));
			try {
				request.getRequestDispatcher("BuyCar.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	public void deleteShop(HttpServletRequest request,HttpServletResponse response){
		if(cartService.goodsRemoveFromShoppingCart(2))
		{
			try {
				request.getRequestDispatcher("BuyCar.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		else	//删除失败~该做的事情
		{
			try {
				request.getRequestDispatcher("BuyCar.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	/**
	 * 添加购物车方法   
	 * @param request
	 * @param response
	 */
	public void addShopCart(HttpServletRequest request,HttpServletResponse response){
		Mall_ShoppingCart shoppingCart =new Mall_ShoppingCart();
		shoppingCart.setShoppingCartId(2);
		shoppingCart.setUserId(1);
		if(cartService.addGoodsToShoppingCart(shoppingCart))
		{
			try {
				request.getRequestDispatcher("BuyCar.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
}
